package gov.child.entities.po;

import gov.child.entities.vo.annotation.Alias;
import gov.child.entities.vo.annotation.IgnoreField;

import javax.persistence.*;
import java.util.Collection;

/**
 * @author fzh
 * @since 2017/9/16
 */
@Entity
@Table(name = "user", schema = "gov_c")
public class EUser {
    @Alias("userId")
    private Integer id;
    private String username;
    private String idNum;
    @IgnoreField
    private String password;
    private String phone;
    private String name;
    private String email;
    private String birthplace;
    private Byte gender;
    private String nation;
    private String homeaddress;
    private String education;
    private String politicalstatus;
    private Integer postcode;
    @IgnoreField
    private Collection<ECollection> collectionsById;
    @IgnoreField
    private Collection<EComplaint> complaintsById;
    @IgnoreField
    private Collection<EComplaint> complaintsById_0;
    @IgnoreField
    private Collection<EConsult> consultsById;
    @IgnoreField
    private Collection<EConsult> consultsById_0;
    @IgnoreField
    private Collection<EEnterpriseDeclareForm> enterpriseDeclareFormsById;
    @IgnoreField
    private Collection<EPersonalDeclareForm> personalDeclareFormsById;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic
    @Column(name = "username", nullable = false, length = 20, updatable = false)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "id_num", nullable = true, length = 18)
    public String getIdNum() {
        return idNum;
    }

    public void setIdNum(String idNum) {
        this.idNum = idNum;
    }

    @Basic
    @Column(name = "password", nullable = false, length = 32, updatable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "phone", nullable = false, length = 15)
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Basic
    @Column(name = "name", nullable = true, length = 32)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "email", nullable = true, length = 32)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Basic
    @Column(name = "birthplace", nullable = true, length = 100)
    public String getBirthplace() {
        return birthplace;
    }

    public void setBirthplace(String birthplace) {
        this.birthplace = birthplace;
    }

    @Basic
    @Column(name = "gender", nullable = true, columnDefinition = "tinyint(1) default 1")
    public Byte getGender() {
        return gender;
    }

    public void setGender(Byte gender) {
        this.gender = gender;
    }

    @Basic
    @Column(name = "nation", nullable = true, length = 8)
    public String getNation() {
        return nation;
    }

    public void setNation(String nation) {
        this.nation = nation;
    }

    @Basic
    @Column(name = "homeaddress", nullable = true, length = 32)
    public String getHomeaddress() {
        return homeaddress;
    }

    public void setHomeaddress(String homeaddress) {
        this.homeaddress = homeaddress;
    }

    @Basic
    @Column(name = "education", nullable = true, length = 2)
    public String getEducation() {
        return education;
    }

    public void setEducation(String education) {
        this.education = education;
    }

    @Basic
    @Column(name = "politicalstatus", nullable = true, length = 4)
    public String getPoliticalstatus() {
        return politicalstatus;
    }

    public void setPoliticalstatus(String politicalstatus) {
        this.politicalstatus = politicalstatus;
    }

    @Basic
    @Column(name = "postcode", nullable = true)
    public Integer getPostcode() {
        return postcode;
    }

    public void setPostcode(Integer postcode) {
        this.postcode = postcode;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EUser user = (EUser) o;

        if (id != null ? !id.equals(user.id) : user.id != null) return false;
        if (username != null ? !username.equals(user.username) : user.username != null) return false;
        if (idNum != null ? !idNum.equals(user.idNum) : user.idNum != null) return false;
        if (password != null ? !password.equals(user.password) : user.password != null) return false;
        if (phone != null ? !phone.equals(user.phone) : user.phone != null) return false;
        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        if (email != null ? !email.equals(user.email) : user.email != null) return false;
        if (birthplace != null ? !birthplace.equals(user.birthplace) : user.birthplace != null) return false;
        if (gender != null ? !gender.equals(user.gender) : user.gender != null) return false;
        if (nation != null ? !nation.equals(user.nation) : user.nation != null) return false;
        if (homeaddress != null ? !homeaddress.equals(user.homeaddress) : user.homeaddress != null) return false;
        if (education != null ? !education.equals(user.education) : user.education != null) return false;
        if (politicalstatus != null ? !politicalstatus.equals(user.politicalstatus) : user.politicalstatus != null)
            return false;
        if (postcode != null ? !postcode.equals(user.postcode) : user.postcode != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (idNum != null ? idNum.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (birthplace != null ? birthplace.hashCode() : 0);
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        result = 31 * result + (nation != null ? nation.hashCode() : 0);
        result = 31 * result + (homeaddress != null ? homeaddress.hashCode() : 0);
        result = 31 * result + (education != null ? education.hashCode() : 0);
        result = 31 * result + (politicalstatus != null ? politicalstatus.hashCode() : 0);
        result = 31 * result + (postcode != null ? postcode.hashCode() : 0);
        return result;
    }

    @OneToMany(mappedBy = "userByUserId")
    public Collection<ECollection> getCollectionsById() {
        return collectionsById;
    }

    public void setCollectionsById(Collection<ECollection> collectionsById) {
        this.collectionsById = collectionsById;
    }

    @OneToMany(mappedBy = "userByUserId")
    public Collection<EComplaint> getComplaintsById() {
        return complaintsById;
    }

    public void setComplaintsById(Collection<EComplaint> complaintsById) {
        this.complaintsById = complaintsById;
    }

    @OneToMany(mappedBy = "userByUserId_0")
    public Collection<EComplaint> getComplaintsById_0() {
        return complaintsById_0;
    }

    public void setComplaintsById_0(Collection<EComplaint> complaintsById_0) {
        this.complaintsById_0 = complaintsById_0;
    }

    @OneToMany(mappedBy = "userByUserId")
    public Collection<EConsult> getConsultsById() {
        return consultsById;
    }

    public void setConsultsById(Collection<EConsult> consultsById) {
        this.consultsById = consultsById;
    }

    @OneToMany(mappedBy = "userByUserId_0")
    public Collection<EConsult> getConsultsById_0() {
        return consultsById_0;
    }

    public void setConsultsById_0(Collection<EConsult> consultsById_0) {
        this.consultsById_0 = consultsById_0;
    }

    @OneToMany(mappedBy = "userByUserId")
    public Collection<EEnterpriseDeclareForm> getEnterpriseDeclareFormsById() {
        return enterpriseDeclareFormsById;
    }

    public void setEnterpriseDeclareFormsById(Collection<EEnterpriseDeclareForm> enterpriseDeclareFormsById) {
        this.enterpriseDeclareFormsById = enterpriseDeclareFormsById;
    }

    @OneToMany(mappedBy = "userByUserId")
    public Collection<EPersonalDeclareForm> getPersonalDeclareFormsById() {
        return personalDeclareFormsById;
    }

    public void setPersonalDeclareFormsById(Collection<EPersonalDeclareForm> personalDeclareFormsById) {
        this.personalDeclareFormsById = personalDeclareFormsById;
    }
}
